package leetcode;

/**
 * <p></p>
 *
 * @author bin.zhang
 * <p/>
 * Revision History:
 * 2020/09/19, 初始化版本
 * @version 1.0
 **/
public class Reverse {

	public int reverse(int x) {
		String xStr = String.valueOf(x);
		StringBuilder sb = new StringBuilder();
		if(x < 0){
			sb.append("-");
		}
		for (int i = xStr.length() - 1; i >= 0; i--){
			if(i == 0 && xStr.charAt(i) == '-'){
				break;
			}
			sb.append(xStr.charAt(i));
		}
		long result = Long.parseLong(sb.toString());
		if(result > Integer.MAX_VALUE || result < Integer.MIN_VALUE){
			return 0;
		}
		return (int) result;
	}


	public static void main(String[] args){
		System.out.println(new Reverse().reverse(-2147483648));
	}
}
